<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\select2\Select2;
use app\modules\Cruise\models\Cruise;
use dosamigos\tinymce\TinyMce;

$cruise = Cruise::find()->where(['status'=>1])->asArray()->all();
$cruise = yii\helpers\ArrayHelper::map($cruise,'id','name');
$city = Yii::$app->params['city'];
(new \Collator('zh-CN'))->asort($city);
?>

<div class="product-form">
    <?php $form = ActiveForm::begin([
                                     'options' => ['enctype' => 'multipart/form-data',],
                                     'layout' => 'horizontal',
                                     'fieldConfig' => [
                                        'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                                        'horizontalCssClasses' => [
                                            'label' => 'col-sm-2',
                                            'wrapper' => 'col-sm-7',
                                            'error' => '',
                                        ],
                                     ],
                                ]); ?>


    <?php echo $form->field($model, 'cruise_id')->widget(Select2::classname(), [
                'data' =>$cruise,
                'language' => 'zh-cn',
                'options' => ['placeholder' => '选择游轮....'],
                'pluginOptions' => [
                    'allowClear' => true
                ],
            ]) ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'go_time',['template'=>'{label}<div class="col-sm-4">{input}{hint}</div>{error}'])
                                        ->widget(kartik\date\DatePicker::classname(),[
                                                    'options' => ['placeholder' => '出发时间'],
                                                    'pluginOptions' => [
                                                        'format' => 'yyyy-mm-dd',
                                                        'autoclose'=>true,
                                                        'todayHighlight' => true
                                                    ]
                                                ]); ?>

    <?= $form->field($model, 'return_time',['template'=>'{label}<div class="col-sm-4">{input}{hint}</div>{error}'])
                                        ->widget(kartik\date\DatePicker::classname(),[
                                                    'options' => ['placeholder' => '返回时间'],
                                                    'pluginOptions' => [
                                                        'format' => 'yyyy-mm-dd',
                                                        'autoclose'=>true,
                                                        'todayHighlight' => true
                                                    ]
                                                ]); ?>

     <?php  echo $form->field($model, 'from_city')->dropdownList($city, ['prompt'=>'选择出发城市']) ?>

     <?php  echo $form->field($model, 'to_city')->dropdownList($city, ['prompt'=>'选择返港城市']) ?>

     <?php  echo $form->field($model, 'go_city')->dropdownList($city, ['prompt'=>'选择上船城市']) ?>

    <?php  echo $form->field($model, 'return_city')->dropdownList($city, ['prompt'=>'选择下船城市']) ?>

    <?= $form->field($model, 'line',['template'=>'{label}<div class="col-md-3">{input}{error}</div>'])->widget(Select2::classname(), [
                'data' => Yii::$app->params['line'],
                'language' => 'zh-cn',
                'options' => ['placeholder' => '选择航线....'],
                'pluginOptions' => [
                    'allowClear' => true,
                ],
            ]) ?>

    <?= $form->field($model, 'type')->inline(true)->radioList(\Yii::$app->params['product_type']) ?>

    <?= $form->field($model, 'stock')->inline(true)->radioList(\Yii::$app->params['product_stock']) ?>

    <?= $form->field($model, 'cost')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'nocost')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'cancel')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'discount')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'visa')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'signup')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'land')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>

    <?= $form->field($model, 'expense')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>
    <?= $form->field($model, 'special')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>
    <?= $form->field($model, 'important')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>
    <?= $form->field($model, 'safe_1')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>            
    <?= $form->field($model, 'safe_2')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>   
    <?= $form->field($model, 'safe_3')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?> 
    <?= $form->field($model, 'cross_talk')->widget(\yii\redactor\widgets\Redactor::className(), [
                                    'clientOptions' => [
                                        'maxHeight' => 300,
                                        'lang' => 'zh_cn',
                                        'plugins' => ['clips', 'fontcolor','imagemanager']
                                    ]
                                ])?>                         


    <?= $form->field($model, 'sale')->textArea(['maxlength' => true, 'rows'=>4]) ?>

    <?= $form->field($model, 'status')->inline(true)->radioList(\Yii::$app->params['status']) ?>

    <hr>
    <div class="form-group text-center">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>
</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">  
    /** 获取出发返港城市*/
    $('#product-cruise_id').on('change', function(event) {
        var cruise_id  = $(this).val();

        $.get("/site/city",{'cruise_id': cruise_id}, function(data){
           var model = jQuery.parseJSON(data);
           
           $('#product-from_city').val(model.from_city);
           $('#product-to_city').val(model.to_city);
        });
    });

    var html = "<div class='item' style='background:#DDD;'>"+ $('.item').first().html() + "</div>"; 


</script>
<?php app\components\JsBlock::end() ?>
